<?php
/**
 * 企业用户管理
 * gemj
 */
if(!defined("SYSTEM_TIME")){
	define("SYSTEM_TIME", isset ( $_SERVER ['REQUEST_TIME'] ) ? $_SERVER ['REQUEST_TIME'] : time ());
}
class Libs_EState
{
	public static function saveEResumeState(array $param){
		$eid  =  !empty($param['eid']) ? $param['eid'] : 0;
		$state = !empty($param['state']) ? $param['state'] : '';

		$db = Db_Resume::instance();

		if(empty($eid)){
			return false;
		}

		$state_str = '';
		if(is_array($state)){
			$state_str = implode(",",$state);
		}

		$q_sql = "select eid from e_resume_state where eid=".$eid;
		$q_eid = $db->getOne($q_sql);

		if(!empty($q_eid)){
			$sql = "update e_resume_state set state='{$state_str}' where eid=".$eid;
		}else{
			$sql = "insert into e_resume_state(eid, state) values ({$eid}, '{$state_str}')";
		}

		$re = $db->query($sql);

		return $re;
	}	


	public static function getEResumeState($eid){
		$db = Db_Resume::instance();

		$q_sql = "select state from e_resume_state where eid=".$eid;
		$q_state = $db->getOne($q_sql);

		if(!empty($q_state)){
			return $q_state;
		}

		return false;
	}

	public static function changeEResumeState(array $param){
		$eid = !empty($param['eid']) ? $param['eid'] : 0;
		$jobid = !empty($param['jobid']) ? $param['jobid']: 0;
		$uid = !empty($param['uid']) ? $param['uid'] : 0;
		$state = !empty($param['state']) ? $param['state'] : 0;

		if($eid == 0 || $jobid == 0 || $uid == 0 || $state == 0)
		{
			return false;	
		}

		$sql = "select id from e_resume_job_relation where uid={$uid} and firm_id={$eid} and job_id={$jobid}";
		$id = $db->getOne($sql);

		if(!empty($id)){
			$csql = "update e_resume_job_relation set state='{$state}' where uid={$uid} and firm_id={$eid} and job_id={$jobid}";
		}else{
			$csql = "insert into e_resume_state(uid, firm_id, job_id, state) values ({$uid},{$eid}, {$jobid}, {$state})";
		}

		$re = $db->query($csql);

		return $re;
	}	

}

?>
